<!--
 * @Author: Chuckie
 * @Email: chuckie@aliyun.com
 * @Date: 2022-11-10 14:35:49
 * @LastEditTime: 2022-11-12 14:32:09
 * @Description: 
 * @FilePath: /zl-web/src/views/basic/enterprise/detail.vue
 *  
-->
<template>
  <div class="app-container">
    <el-form :model="state.form" label-width="120px">
      <el-form-item :label="$t('tenant.table.code')">
        <el-input v-model="state.form.code" />
      </el-form-item>
      <el-form-item :label="$t('tenant.table.name')">
        <el-input v-model="state.form.name" />
      </el-form-item>
      <el-form-item :label="$t('tenant.table.des')">
        <el-input v-model="state.form.des" />
      </el-form-item>


  
      



      <el-form-item>
        <el-button type="primary" @click="onSubmit">{{$t('common.button.save')}}</el-button>
        <el-button @click="onCancel">{{$t('common.button.back')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { create, select, selectOne, update } from './api/base-tenant'
const route = useRoute()
const router = useRouter()

const { proxy }: any = getCurrentInstance()
const state = reactive({
  form: {
    id: '',
    name: '',
    code: '',
    des: '',
    pid:''
    
  },
  
})

const onCancel = () => {
  router.back()
}

const onSubmit = async () => {
  if (route.params.id) {
    const data = await update(state.form)
    proxy.$message({ message: proxy.$t('common.message.editSuccessfully'), type: 'success' })
  } else {
    state.form.pid = '0'
    const data = await create(state.form)
    proxy.$message({ message: proxy.$t('common.message.editSuccessfully'), type: 'success' })
  }
  router.back();

}

const onSelectOne = async (id: string) => {
  const data = await selectOne(id)
  state.form = { ...data.data }

}


onMounted(() => {
  route.params.id && !Array.isArray(route.params.id) && onSelectOne(route.params.id)

})

</script>

<style lang="scss" scoped>
.el-input {
  width: 300px;
}

.el-select {
  width: 300px;
}

.el-textarea {
  width: 300px;
}
</style>
